<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <meta name="author" content="逯灿灿">
    <title></title>
    <style>
    span{
        display: inline-block;
        /* background-color: #aaa; */
        width: 30px;
        height: 30px;
        background-size: 100%;   
        background-image: url('./img/22.png');
        background-position: 0 0;
    }
    .active{
        background-image: url('./img/22.png');
        background-position: 0px -46px;
    }
    .active2{
         background-color: blue; 
        /* display: inline-block;
        width: 30px;
        height: 30px;
        background-size: 100%;  
        background-image: url(2.png);
        background-position: 0 0; */

    }
    </style>
</head>

<body>
    <span></span>
    <span></span>
    <span></span>
    <span></span>
    <span></span>

</body>

</html>
<script>
    var spans = document.querySelectorAll('span');

     var msg = [
        "很不满意|差得太离谱，与卖家描述的严重不符，非常不满",
        "不满意|部分有破损，与卖家描述的不符，不满意",
        "一般|质量一般，没有卖家描述的那么好",
        "满意|质量不错，与卖家描述的基本一致，还是挺满意的",
        "非常满意|质量非常好，与卖家描述的完全一致，非常满意"
    ];
    // 记录分数 score = this.index
    var score = 0;
    for(var i = 0;i<spans.length;i++){
        spans[i].index = i;
        spans[i].onmouseover = function(){
            console.log(this.index);
            // if(this.index>1){
                 bianli(this.index+1);
            // }else{
            //     bianli2(this.index);
            // }
        }
        spans[i].onclick = function(){
            score = this.index + 1;
        }
        spans[i].onmouseout = function(){
            // for(var i = 0;i<=this.index;i++){
            //     spans[i].className = '';
            // }
            bianli(score);
        }
    }
    function bianli(length){
        for(var i = 0; i < spans.length;i ++){
            if(i<length){
                spans[i].className = 'active';
            }else{
                spans[i].className = '';
            }
        }
    }
    // function bianli2(length){
    //     for(var i = 0; i <= length;i ++){
    //         spans[i].className = 'active2';
    //     }
    // }
</script>